//-----------------------------------------------------------------------
// <copyright file="CatalogService.cs" company="Pyramid Consulting">
//     Copyright (c) Pyramid Consulting. All rights reserved.
// </copyright>
//-----------------------------------------------------------------------	

using System;
using System.Collections;
using MyFramework;
using MIMS.WRS.Entities;
using MIMS.WRS.Data;
    
namespace MIMS.WRS.Business
{   
	/// <summary>
	/// 
	/// </summary> 
    public class CatalogService
    {
        #region Catalog

        public static void CreateCatalog(Catalog catalog)
        {            
            try
            {
                CatalogDAO catalogDAO = new CatalogDAO();
                catalogDAO.CreateCatalog(catalog);
            }
            catch (BusinessException)
            {
                throw;
            }
            catch (Exception ex)
            {
                // log this exception
                Logger.Error(ex);
                // wrap it and rethrow
                throw new BusinessException(SR.BusinessCreateCatalogException, ex);
            }
        }        

        public static void UpdateCatalog(Catalog catalog)
        {            
            try
            {
                CatalogDAO catalogDAO = new CatalogDAO();
                catalogDAO.UpdateCatalog(catalog);
            }
            catch (BusinessException)
            {
                throw;
            }
            catch (Exception ex)
            {
                // log this exception
                Logger.Error(ex);
                // wrap it and rethrow
                throw new BusinessException(SR.BusinessUpdateCatalogException, ex);
            }
        }        

        public static void DeleteCatalog(int catalogID)
        {            
            try
            {
                CatalogDAO catalogDAO = new CatalogDAO();
                catalogDAO.DeleteCatalog(catalogID);
            }
            catch (BusinessException)
            {
                throw;
            }
            catch (Exception ex)
            {
                // log this exception
                Logger.Error(ex);
                // wrap it and rethrow
                throw new BusinessException(SR.BusinessDeleteCatalogException, ex);
            }
        }
        
        public static Catalog GetCatalog(int catalogID)
        {            
            try
            {
                CatalogDAO catalogDAO = new CatalogDAO();
                return catalogDAO.GetCatalog(catalogID);                
            }
            catch (BusinessException)
            {
                throw;
            }
            catch (Exception ex)
            {
                // log this exception
                Logger.Error(ex);
                // wrap it and rethrow
                throw new BusinessException(SR.BusinessGetCatalogException, ex);
            }
        }                

        public static CatalogCollection GetCatalogs(CatalogColumns orderBy, OrderDirection orderDirection)
        {            
            try
            {
                CatalogDAO catalogDAO = new CatalogDAO();
                return catalogDAO.GetCatalogs(orderBy, orderDirection);
            }
            catch (BusinessException)
            {
                throw;
            }
            catch (Exception ex)
            {
                // log this exception
                Logger.Error(ex);
                // wrap it and rethrow
                throw new BusinessException(SR.BusinessGetCatalogsException, ex);
            }
        }        

        public static CatalogCollection GetCatalogs(CatalogColumns orderBy, OrderDirection orderDirection, int page, int pageSize, out int totalRecords)
        {            
            try
            {
                CatalogDAO catalogDAO = new CatalogDAO();
                return catalogDAO.GetCatalogs(orderBy, orderDirection, page, pageSize, out totalRecords);
            }
            catch (BusinessException)
            {
                throw;
            }
            catch (Exception ex)
            {
                // log this exception
                Logger.Error(ex);
                // wrap it and rethrow
                throw new BusinessException(SR.BusinessGetCatalogsException, ex);
            }
        }        

        #endregion

		public static Catalog GetCatalog(string catalogName)
		{            
			try
			{
				CatalogDAO catalogDAO = new CatalogDAO();
				return catalogDAO.GetCatalog(catalogName);                
			}
			catch (BusinessException)
			{
				throw;
			}
			catch (Exception ex)
			{
				// log this exception
				Logger.Error(ex);
				// wrap it and rethrow
				throw new BusinessException(SR.BusinessGetCatalogException, ex);
			}
		}    
    }
}